package threadpool;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3, // 核心线程数量
                10, // 线程池的总数量
                60, // 临时线程空闲时间
                TimeUnit.SECONDS, // 临时线程空闲时间的单位
                new LinkedBlockingQueue<Runnable>(5), // 阻塞队列
                Executors.defaultThreadFactory(), // 创建线程的方式
                new ThreadPoolExecutor.AbortPolicy() // 任务拒绝策略
        ); // 7个参数
        while (true) {
            Socket s = ss.accept();
            ThreadSocket ts = new ThreadSocket(s);
            // new Thread(ts).start();
            pool.submit(ts); // 一旦有任务就提交

        }
        // ss.close();

    }
}
